#pragma once

// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license

#include "gl.h"

// ----------------------------------------------------------------------------
// Class "UniformVar"
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------

class UniformVar
{
public:

    enum Type { NONE, F, F3, F4 };
    union Value
    {
        GLfloat f;
        GLfloat f3[3];
        GLfloat f4[4];
    };

    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

    UniformVar() 
    {
        type = NONE;
    }

    UniformVar(float v) 
    {
        value.f = v;
        type = F;
    }

    UniformVar(float a, float b, float c) 
    {
        type = F3;
        value.f3[0] = a;
        value.f3[1] = b;
        value.f3[2] = c;
    }

    UniformVar(float a, float b, float c, float d) 
    {
        type = F4;
        value.f4[0] = a;
        value.f4[1] = b;
        value.f4[2] = c;
        value.f4[3] = d;
    }

    // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

    void setInRenderContext(int loc)
    {
        if(type == F)
        {
            glUniform1f(loc, value.f);
        }
        else if(type == F3)
        {
            glUniform3fv(loc, 1, value.f3);
        }
        else if(type == F4)
        {
            glUniform4fv(loc, 1, value.f4);
        }
        else
        {
            ASSERT(false);
        }
    }

private:
    Value value;
    Type type;
};

